import 'package:flutter/material.dart';

import '../../res/TestUserAgreementData.dart';

class UserAgreement extends StatelessWidget {
  const UserAgreement({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("用户协议"),
      ),
      body: const _UserAgreementBody(),
    );
  }
}

class _UserAgreementBody extends StatelessWidget {
  const _UserAgreementBody({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.all(20),
      child: const Column(
        children: [
          Expanded(
            child: _AgreementText(),
          ),
          SizedBox(height: 15,),
          _backButton()
        ],
      ),
    );
  }
}

class _AgreementText extends StatelessWidget {
  const _AgreementText({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(12),
      decoration: BoxDecoration(
        color: Colors.grey.shade200,
        borderRadius: BorderRadius.circular(10),
      ),
      child: ListView(
        children: [
          Text(
            TestUserAgreementData(),
            style: const TextStyle(fontSize: 18),
          ),
        ],
      ),
    );
  }
}

class _backButton extends StatefulWidget {
  const _backButton({super.key});

  @override
  State<_backButton> createState() => _backButtonState();
}

class _backButtonState extends State<_backButton> {

  void toBack(){
    Navigator.of(context).pop();
  }

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 40,
      width: MediaQuery.of(context).size.width,
      child: ElevatedButton(
        onPressed: toBack,
        style: ButtonStyle(
          shape: MaterialStateProperty.all(
              RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(10)
              )
          ),
        ),
        child: const Text("返回上一页",style: TextStyle(fontSize: 16),),
      ),
    );
  }
}



